/*
 * @Descripttion: 
 * @Mender: zhtao
 * @Date: 2020-05-21 18:45:53
 * @LastEditors: zhtao
 * @LastEditTime: 2020-06-04 10:58:08
 */
import * as API_Address from '../../api/address'
import * as API_Members from '../../api/members'
import * as API_Distribution from '../../api/distribution'
import {
  Foundation,
  RegExp
} from '../../ui-utils/index'
let util = require('../../utils/util.js')
const App = getApp()

Page({
  data: {
    finished: false,
    from: '', // 页面涞源
    fenrun: {
      yifenrun: 0,
      daifenrun: 0
    },
    fans: {
      fans: 0,
      loyal_fans: 0
    },
    query: "",
    yuan_fans:'',
    //缘粉
    yuan_fans_count:0,
    yuan_fans_setting:false,
  },

  onLoad(options) { // 设置页面来源
    wx.showShareMenu({
      withShareTicket: true
    })
    this.setData({
      from: options.from || ''
    })
  }, 
  /** 分享 */
  onShareAppMessage: function () {
    return {
      title: '欧品国际商城',
      desc: '注册有惊喜',
      path: '/pages/auth/register_activity/register_activity' + this.data.query,
      imageUrl: 'https://img.oupinguoji.cn/3dc839e2e0bf757ca49d7b0da6edfc1.jpg'
    }
  },
  async onShow() {
    this.getFenrun()
    this.getFans()
    let response = await API_Distribution.generateShortLink();
    let query = response.message.substring(
      response.message.indexOf("?"),
      response.message.length
    );
    this.setData({
      query
    })
  },
  goShareDetail(e) {
    wx.navigateTo({
      url: "/ucenter/share-detail/share-detail"
    })
  },
  //粉丝列表
  goFansDetail(e){
    let type = e.currentTarget.dataset.fans
    wx.navigateTo({
      url: "/ucenter/fans-detail/fans-detail?type="+type
    })
  },
  getFans() {
    API_Distribution.getFans().then(response => {
      this.setData({
        fans: response
      })
    }); 

    /* 缘粉 */
    API_Distribution.getYuanFansSettings().then(res => {
      this.setData({yuan_fans:JSON.parse(res).fasns})
      if (this.data.yuan_fans) {
        this.setData({yuan_fans_setting:true})
        API_Distribution.getYuanFansCount().then(data => {
          this.setData({yuan_fans_count : data})
        });
      }
    });
  },

  getFenrun() {  
    API_Distribution.getPromote().then((response) => {
      response.yifenrun = Foundation.formatPrice(response.yifenrun);
      response.daifenrun = Foundation.formatPrice(response.daifenrun);
      this.setData({
        fenrun: response
      })
    })
  },
  
})